--[[

  Copyright (c) 2012-2013 Baby-Bus.com 
  http://www.babybus.com/ 

]] 




--------------------------
-- 引入命名空间
--------------------------
-- local BaseLayer = import("app.common.layer.BaseLayer")




--[[
	类
--]]


local M = classLayerTouch("Main")




--------------------------
-- 构造函数
--------------------------

function M:ctor(params)
	-- [超类调用]
	M.super.ctor(self, params)
	-- [本类调用]

end

--------------------------
-- 渲染
--------------------------

function M:onRender()
	-- [超类调用]
	M.super.onRender(self)

	-- [本类调用]
	-- 加载节点
	self:loadNodes()
end

-- 加载节点
function M:loadNodes()
	self:loadDragonBonesData()
	self:createArmature()
end

-- 加载渲染以外的其他操作
function M:onEnterTransitionFinish()
	--
end

-- 加载骨骼信息
function M:loadDragonBonesData()
	dragonBones.CCFactory:loadDragonBonesData("effect/effect_ske.json", "hd", 1.0)
	dragonBones.CCFactory:loadTextureAtlasData("effect/effect_tex.json", "hd", 1.0)

	dragonBones.CCFactory:loadDragonBonesData("effect/effect_ske.json", "sd", 0.5)
	dragonBones.CCFactory:loadTextureAtlasData("effect/effect_sd_tex.json", "sd", 2.0)
end

-- 创建骨骼
function M:createArmature()
	self.armatureDisplayA = CCSpriteExtend.extend(dragonBones.CCFactory:buildArmatureDisplay("flower", "hd", "", "hd")) 
	:p(541, 342):to(self):bindTouchLocate()
	self.armatureDisplayB = CCSpriteExtend.extend(dragonBones.CCFactory:buildArmatureDisplay("flower", "hd", "", "sd"))
	:p(968, 413):to(self):bindTouchLocate()
	
	self.armatureDisplayC = CCSpriteExtend.extend(dragonBones.CCFactory:buildArmatureDisplay("flower", "sd", "", "hd"))
	:p(386, 103):to(self):bindTouchLocate()
	
	self.armatureDisplayD = CCSpriteExtend.extend(dragonBones.CCFactory:buildArmatureDisplay("flower", "sd", "", "sd"))
	:p(892, 103):to(self):bindTouchLocate()
	self:changeAnimation()
end

function  M:changeAnimation()
	local animationName = self.armatureDisplayA:getAnimation():getLastAnimationName();

	print("animationName===", S.isEmpty(animationName))
	if not S.isEmpty(animationName) then
		local animationNames = self.armatureDisplayA:getAnimation():getAnimationNames();
		dump(animationNames)
		-- self.armatureDisplayA:getAnimation():play("skill").playTimes = 0;
		self.armatureDisplayA.getAnimation():play("skill"):setPlayTimes(0)

	else 
		-- self.armatureDisplayA:getAnimation():play().playTimes = 0;
		self.armatureDisplayA:getAnimation():play():setPlayTimes(0)

	end

	animationName = self.armatureDisplayA:getAnimation():getLastAnimationName();
	-- set调用
	self.armatureDisplayB:getAnimation():play("skill"):setPlayTimes(0)
	self.armatureDisplayC:getAnimation():play("skill"):setPlayTimes(0)
	self.armatureDisplayD:getAnimation():play("skill"):setPlayTimes(0)
	-- .调用
	-- self.armatureDisplayB:getAnimation():play("skill").playTimes = 0;
	-- self.armatureDisplayC:getAnimation():play("skill").playTimes = 0;
	-- self.armatureDisplayD:getAnimation():play("skill").playTimes = 0;
end



--------------------------
-- 触控
-------------------------- 

function M:onTouchBegan(x, y, touches)
	--  触控有效
	return true 
end

function M:onTouchMoved(x, y, touches)
	--   
end

function M:onTouchEnded(x, y, touches)
	--  
end



--------------------------
-- 功能函数
--------------------------




--------------------------
-- 属性
--------------------------




--------------------------
-- 父类重写
--------------------------




--------------------------
-- 节点移除
--------------------------


----------------------------------------------------
-- 析构
--------------------------

function M:onDestructor()
	-- [超类调用]
	M.super.onDestructor(self)
	-- [本类调用]

end








return M






